package com.linsir.lin.controller.omp;

import com.linsir.core.BaseResponse;
import com.linsir.lin.dto.GridDTO;
import com.linsir.lin.dto.PositionDTO;
import com.linsir.lin.pojo.Permission;

import com.linsir.lin.pojo.Position;
import com.linsir.lin.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @author ：huangqg
 * @date ：Created in 2021/7/10 16:35
 * @description：职务
 * @modified By：
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/position")
public class PositionController {
    @Autowired
    private PositionService positionService;

    /**
     * 职务列表
     * @param page
     * @param limit
     * @param searchParams
     * @return
     * @throws IllegalAccessException
     * @throws IOException
     * @throws InvocationTargetException
     */
    @RequestMapping(value = "/grid",method = {RequestMethod.POST,RequestMethod.GET})
    public GridDTO<PositionDTO> grid(String page,
                                     String limit,
                                     String searchParams) throws IllegalAccessException, IOException, InvocationTargetException  {
        return positionService.grid(page,limit,searchParams);
    }

    /**
     * 职务列表
     * @param page
     * @param limit
     * @param organId
     * @param searchParams
     * @return
     * @throws IllegalAccessException
     * @throws IOException
     * @throws InvocationTargetException
     */
    @RequestMapping(value = "/gridList",method = {RequestMethod.POST,RequestMethod.GET})
    public GridDTO<PositionDTO> gridList(String page,
                                     String limit, Integer organId,
                                     String searchParams) throws IllegalAccessException, IOException, InvocationTargetException  {
        return positionService.gridList(page,limit,organId,searchParams);
    }

    /**
     * 添加或修改职务
     * @param map
     * @param organId
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/add/{organId}",method = {RequestMethod.POST})
    public BaseResponse<Boolean> doAddPosition(@RequestBody Map<String ,Object> map,@PathVariable("organId") Integer organId)throws ParseException {
        return positionService.addOrUpdate(map,organId);
    }

    /**
     * 批量删除职务
     * @param ids
     * @return
     */
    @RequestMapping(value = "/batchDel",method = {RequestMethod.GET})
    public BaseResponse<Boolean> batchDel(String ids){
        return positionService.batchDel(ids);
    }

    /**
     * 编辑职务
     * @param map
     * @param accountID
     * @return
     */
    @RequestMapping(value = "/edit/{positionID}",method = {RequestMethod.POST})
    public BaseResponse<Boolean> editPosition(@RequestBody Map<String,Object> map, @PathVariable("positionID") String accountID) throws ParseException {
        return positionService.edit(map,Integer.parseInt(accountID));
    }
}
